import subprocess
import threading
import time
import build_log_analyse

# 假设你的.cmd文件名为 example.cmd
cmd_file = 'env.cmd'

def run_cmd(cmd_file):
    try:
        print("Building...")
        result = subprocess.run(cmd_file, shell=True, check=True, text=True, capture_output=True)
        print("Build finished")
        return True
    except subprocess.CalledProcessError as e:
        print("Error: ", e)
        print("Build failed")
        return False
    except Exception as e:
        print("Error: ", e)
        print("Build failed")
        return False
        
def analyse(file):
    while(1):
        time.sleep(1)
        build_log_analyse.analyse(file)

if __name__ == "__main__":
    thread_run_cmd = threading.Thread(target=run_cmd, args=(cmd_file,))
    thread_run_cmd.start()
    thread_analyse = threading.Thread(target=analyse, args=('build.log',))
    thread_analyse.start()

    thread_run_cmd.join()
    thread_analyse.join()
